/*
 *  Copyright 2009 Rohan Ranade.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package com.google.code.jqif;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * A category
 * 
 * @author Rohan Ranade
 */
public class Category {

    private String name;
    private String description;
    private boolean taxRelated;
    private boolean income;
    private long budgetAmount;
    private String taxScheduleInfo;

    private Category parent;
    private List<Category> children;

    public void setParent(Category parent) {
        if (this.parent != null) {
            this.parent.removeChild(this);
        }
        this.parent = parent;
        if (this.parent != null) {
            this.parent.addChild(this);
        }
    }

    public Category getParent() {
        return parent;
    }

    public List<Category> getChildren() {
        if (children == null) {
            return Collections.emptyList();
        }
        return Collections.unmodifiableList(children);
    }

    private void addChild(Category child) {
        if (children == null) {
            children = new ArrayList<Category>();
        }
        children.add(child);
    }

    private void removeChild(Category child) {
        if (children == null) {
            throw new IllegalStateException("Cannot remove child when there is none");
        }
        children.remove(child);
    }

    public long getBudgetAmount() {
        return budgetAmount;
    }

    public void setBudgetAmount(long budgetAmount) {
        this.budgetAmount = budgetAmount;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isTaxRelated() {
        return taxRelated;
    }

    public void setTaxRelated(boolean taxRelated) {
        this.taxRelated = taxRelated;
    }

    public String getTaxScheduleInfo() {
        return taxScheduleInfo;
    }

    public void setTaxScheduleInfo(String taxScheduleInfo) {
        this.taxScheduleInfo = taxScheduleInfo;
    }

    public Category() {
    }

    public boolean isIncome() {
        return income;
    }

    public void setIncome(boolean income) {
        this.income = income;
    }
}
